/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-7
  File:    BadResultException.cpp  
  Description: 

*/

#include "stdafx.h"

using namespace System;
using namespace System::Security;
using namespace System::Runtime::Serialization;

#include "BadResultException.h"

namespace SL
{
	namespace M
	{
		BadResultException::BadResultException()
			: _Error(0)
		{

		}

		BadResultException::BadResultException(System::String ^ message)
			: ApplicationException(message),
			_Error(0)
		{
		}

		BadResultException::BadResultException(System::String^ message, Exception^ inner)
			: ApplicationException(message, inner),
			_Error(0)
		{

		}

		BadResultException::BadResultException(int errorCode, System::String ^ message)
			: ApplicationException(message),
			_Error(errorCode)
		{
		}

		BadResultException::BadResultException(const m::bad_result_exception * inner)
			: ApplicationException(gcnew String(inner->what())),
			_Error(inner->ErrorCode)
		{
		}

		void BadResultException::RethrowAsWin32Exception()
		{
			throw gcnew System::ComponentModel::Win32Exception(_Error & 0xFFFF);
		}

		BadResultException::BadResultException(SerializationInfo^ info, StreamingContext context)
			: ApplicationException(info, context)
		{
			_Error = (Int32)info->GetValue("error", Int32::typeid);
		}

		void BadResultException::GetObjectData(SerializationInfo^ info, StreamingContext context)
		{
			Exception::GetObjectData(info, context);
			info->AddValue("error", _Error, Int32::typeid);
		}

		String ^ BadResultException::ToString()
		{
			return ApplicationException::ToString() + String::Format(System::Globalization::CultureInfo::InvariantCulture, L" [{0:X8}]", _Error);
		}

		int BadResultException::ErrorCode::get()
		{
			return _Error;
		}


	}
}